package com.wsoft.dc.controller;

import com.wsoft.dc.query.config.entity.ConfigEntityInsertQuery;
import com.wsoft.dc.query.config.entity.ConfigEntityListQuery;
import com.wsoft.dc.query.config.entity.ConfigEntityUpdateQuery;
import com.wsoft.dc.service.IDcConfigEntityService;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 待办实体对象 前端控制器
 * @author Z001
 * @since 2024年12月17日 16:18:19
 */
@RestController
@Tag(name = "子项配置")
@RequestMapping("/dc/config/entity")
public class DcConfigEntityController {

    @Resource
    private IDcConfigEntityService configEntityService;

    @Operation(summary = "新增待办配置子项", description = "新增待办配置子项")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ConfigEntityInsertQuery query) {
        boolean b = configEntityService.insertConfigEntity(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "修改待办配置子项", description = "修改待办配置子项")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ConfigEntityUpdateQuery query) {
        boolean b = configEntityService.updateConfigEntity(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "待办配置子项详情页面", description = "待办配置子项详情页面")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(configEntityService.getConfigEntityInfo(id));
    }

    @Operation(summary = "删除待办配置子项", description = "删除待办配置子项")
    @GetMapping("/delete")
    public ResponseResult dropConfig(@RequestParam("id") Long id) {
        boolean b = configEntityService.deleteConfigEntity(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "查询待办配置子项列表", description = "查询待办配置子项列表")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ConfigEntityListQuery query) {
        return ResponseResult.success(configEntityService.listConfigEntity(query));
    }

}
